/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.core.domain;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import info.peigen.hotpot.common.core.domain.DomainObject;
import info.peigen.hotpot.common.core.enums.YesOrNo;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import java.util.List;

import static info.peigen.hotpot.common.core.enums.YesOrNo.N;
import static info.peigen.hotpot.common.core.enums.YesOrNo.Y;


/**
 * <b>(CustomerPermission)</b>
 * 客户权限
 * 这里以json的方式存储,可随意增加
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/28
 */
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CustomerPermission extends DomainObject {
    /** 可登录 */
    @Builder.Default
    YesOrNo login              = Y;
    /** 可修改登录密码 */
    @Builder.Default
    YesOrNo editLoginPassword  = Y;
    /** 可支付 */
    @Builder.Default
    YesOrNo pay                = N;
    /** 可修改交易密码 */
    @Builder.Default
    YesOrNo editPayPassword    = N;
    /** 是否发送30天证件过期提醒 */
    @Builder.Default
    YesOrNo sendThirtyReminder = N;
    /** 是否发送90天证件过期提醒 */
    @Builder.Default
    YesOrNo sendNinetyReminder = N;

    public void check() {
        Assert.isTrue(ObjectUtil.isAllNotEmpty(login, pay, sendThirtyReminder, sendNinetyReminder), "权限不得为空!");
    }

    public boolean permissionAllClose() {
        List<YesOrNo> allPermission = Lists.newArrayList(login, editLoginPassword, pay, editPayPassword, sendThirtyReminder, sendNinetyReminder);
        return allPermission.stream().noneMatch(p -> p == Y);
    }

}
